package magicbook.gtlitecore.common.metatileentities.multi.electric;

import gregtech.api.capability.IMultipleTankHandler;
import gregtech.api.capability.impl.MultiblockRecipeLogic;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.multiblock.IMultiblockPart;
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController;
import gregtech.api.pattern.BlockPattern;
import gregtech.api.pattern.FactoryBlockPattern;
import gregtech.api.util.RelativeDirection;
import gregtech.client.renderer.ICubeRenderer;
import gregtech.client.renderer.texture.Textures;
import gregtech.common.blocks.BlockComputerCasing;
import gregtech.common.blocks.MetaBlocks;
import magicbook.gtlitecore.api.recipe.GTLiteRecipeMaps;
import magicbook.gtlitecore.api.utils.GTLiteUtility;
import magicbook.gtlitecore.client.renderer.texture.GTLiteTextures;
import magicbook.gtlitecore.common.blocks.BlockScienceCasing;
import magicbook.gtlitecore.common.blocks.GTLiteMetaBlocks;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

import static gregtech.api.unification.material.Materials.Helium;
import static gregtech.api.unification.material.Materials.Hydrogen;

//  TODO redo workable handler of this machine (if possible, add a new renderer in middle part of structure).
public class MetaTileEntityVirtualCosmosSimulator extends RecipeMapMultiblockController {

    public MetaTileEntityVirtualCosmosSimulator(ResourceLocation metaTileEntityId) {
        super(metaTileEntityId, GTLiteRecipeMaps.VIRTUAL_COSMOS_SIMULATOR_RECIPES);
        this.recipeMapWorkable = new VirtualCosmosSimulatorRecipeLogic(this);
    }

    @Override
    public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
        return new MetaTileEntityVirtualCosmosSimulator(metaTileEntityId);
    }

    @NotNull
    @Override
    protected BlockPattern createStructurePattern() {
        return FactoryBlockPattern.start(RelativeDirection.RIGHT, RelativeDirection.FRONT, RelativeDirection.UP)
                .aisle("                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "               C C               ", "               C C               ", "               C C               ", "            CCCCCCCCC            ", "               C C               ", "            CCCCCCCCC            ", "               C C               ", "               C C               ", "               C C               ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "               C C               ", "             GGC CGG             ", "            GGGC CGGG            ", "           GGGGC CGGGG           ", "          GGGGDDDDDGGGG          ", "          GGGDDCDCDDGGG          ", "         CCCCDCCDCCDCCCC         ", "             DDDDDDD             ", "         CCCCDCCDCCDCCCC         ", "          GGGDDCDCDDGGG          ", "          GGGGDDDDDGGGG          ", "           GGGGC CGGGG           ", "            GGGC CGGG            ", "             GGC CGG             ", "               C C               ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "               C C               ", "             GGC CGG             ", "           GGGGC CGGGG           ", "          GGG   D   GGG          ", "         GGG    D    GGG         ", "         GG  DDDDDDD  GG         ", "        GG  DD     DD  GG        ", "        GG  D  EEE  D  GG        ", "       CCC  D EAAAE D  CCC       ", "          DDD EAAAE DDD          ", "       CCC  D EAAAE D  CCC       ", "        GG  D  EEE  D  GG        ", "        GG  DD     DD  GG        ", "         GG  DDDDDDD  GG         ", "         GGG    D    GGG         ", "          GGG   D   GGG          ", "           GGGGC CGGGG           ", "             GGC CGG             ", "               C C               ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "               C C               ", "            GGGC CGGG            ", "          GGG   D   GGG          ", "         GG     D     GG         ", "        GG             GG        ", "        G               G        ", "       GG               GG       ", "       G                 G       ", "       G                 G       ", "      CC                 CC      ", "        DD             DD        ", "      CC                 CC      ", "       G                 G       ", "       G                 G       ", "       GG               GG       ", "        G               G        ", "        GG             GG        ", "         GG     D     GG         ", "          GGG   D   GGG          ", "            GGGC CGGG            ", "               C C               ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "               C C               ", "           GGGCCCCCGGG           ", "         GGG    D    GGG         ", "        GG      B      GG        ", "       GG       B       GG       ", "       G                 G       ", "      GG                 GG      ", "      G                   G      ", "      G                   G      ", "      C                   C      ", "     CC                   CC     ", "      CDBB             BBDC      ", "     CC                   CC     ", "      C                   C      ", "      G                   G      ", "      G                   G      ", "      GG                 GG      ", "       G                 G       ", "       GG       B       GG       ", "        GG      B      GG        ", "         GGG    D    GGG         ", "           GGGCCCCCGGG           ", "               C C               ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "                                 ", "                                 ", "               C C               ", "          GGGGGC CGGGGG          ", "        GGG     D     GGG        ", "       GG    EEEBEEE    GG       ", "      GG                 GG      ", "      G                   G      ", "     GG                   GG     ", "     G                     G     ", "     G                     G     ", "     G E                 E G     ", "     G E                 E G     ", "    CC E                 E CC    ", "      DB                 BD      ", "    CC E                 E CC    ", "     G E                 E G     ", "     G E                 E G     ", "     G                     G     ", "     G                     G     ", "     GG                   GG     ", "      G                   G      ", "      GG                 GG      ", "       GG    EEEBEEE    GG       ", "        GGG     D     GGG        ", "          GGGGGC CGGGGG          ", "               C C               ", "                                 ", "                                 ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "                                 ", "               C C               ", "           GGGCCCCCGGG           ", "        GGG     D     GGG        ", "       GG       B       GG       ", "      G                   G      ", "     GG                   GG     ", "     G                     G     ", "     G                     G     ", "    G                       G    ", "    G                       G    ", "    G                       G    ", "    C                       C    ", "   CC                       CC   ", "    CDB                   BDC    ", "   CC                       CC   ", "    C                       C    ", "    G                       G    ", "    G                       G    ", "    G                       G    ", "     G                     G     ", "     G                     G     ", "     GG                   GG     ", "      G                   G      ", "       GG       B       GG       ", "        GGG     D     GGG        ", "           GGGCCCCCGGG           ", "               C C               ", "                                 ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "               C C               ", "            GGGC CGGG            ", "         GGG    D    GGG         ", "       GG    EEEBEEE    GG       ", "      G                   G      ", "     G                     G     ", "     G                     G     ", "    G                       G    ", "    G                       G    ", "    G                       G    ", "   G                         G   ", "   G E                     E G   ", "   G E                     E G   ", "  CC E                     E CC  ", "    DB                     BD    ", "  CC E                     E CC  ", "   G E                     E G   ", "   G E                     E G   ", "   G                         G   ", "    G                       G    ", "    G                       G    ", "    G                       G    ", "     G                     G     ", "     G                     G     ", "      G                   G      ", "       GG    EEEBEEE    GG       ", "         GGG    D    GGG         ", "            GGGC CGGG            ", "               C C               ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "             GGC CGG             ", "          GGG   D   GGG          ", "        GG      B      GG        ", "      GG                 GG      ", "     GG                   GG     ", "     G                     G     ", "    G                       G    ", "    G                       G    ", "   G                         G   ", "   G                         G   ", "   G                         G   ", "  G                           G  ", "  G                           G  ", "  C                           C  ", "   DB                       BD   ", "  C                           C  ", "  G                           G  ", "  G                           G  ", "   G                         G   ", "   G                         G   ", "   G                         G   ", "    G                       G    ", "    G                       G    ", "     G                     G     ", "     GG                   GG     ", "      GG                 GG      ", "        GG      B      GG        ", "          GGG   D   GGG          ", "             GGC CGG             ", "                                 ", "                                 ")
                .aisle("                                 ", "               C C               ", "           GGGGC CGGGG           ", "         GG     D     GG         ", "       GG       B       GG       ", "      G                   G      ", "     G                     G     ", "    G                       G    ", "    G                       G    ", "   G                         G   ", "   G                         G   ", "  G                           G  ", "  G                           G  ", "  G                           G  ", "  G                           G  ", " CC                           CC ", "   DB                       BD   ", " CC                           CC ", "  G                           G  ", "  G                           G  ", "  G                           G  ", "  G                           G  ", "   G                         G   ", "   G                         G   ", "    G                       G    ", "    G                       G    ", "     G                     G     ", "      G                   G      ", "       GG       B       GG       ", "         GG     D     GG         ", "           GGGGC CGGGG           ", "               C C               ", "                                 ")
                .aisle("                                 ", "             GGC CGG             ", "          GGG   D   GGG          ", "        GG             GG        ", "       G                 G       ", "     GG                   GG     ", "     G                     G     ", "    G                       G    ", "   G                         G   ", "   G                         G   ", "  G                           G  ", "  G                           G  ", "  G                           G  ", " G                             G ", " G                             G ", " C                             C ", "  D                           D  ", " C                             C ", " G                             G ", " G                             G ", "  G                           G  ", "  G                           G  ", "  G                           G  ", "   G                         G   ", "   G                         G   ", "    G                       G    ", "     G                     G     ", "     GG                   GG     ", "       G                 G       ", "        GG             GG        ", "          GGG   D   GGG          ", "             GGC CGG             ", "                                 ")
                .aisle("                                 ", "            GGGC CGGG            ", "         GGG    D    GGG         ", "        G               G        ", "      GG                 GG      ", "     G                     G     ", "    G                       G    ", "    G                       G    ", "   G                         G   ", "  G                           G  ", "  G                           G  ", "  G                           G  ", " G                             G ", " G                             G ", " G                             G ", " C                             C ", "  D                           D  ", " C                             C ", " G                             G ", " G                             G ", " G                             G ", "  G                           G  ", "  G                           G  ", "  G                           G  ", "   G                         G   ", "    G                       G    ", "    G                       G    ", "     G                     G     ", "      GG                 GG      ", "        G               G        ", "         GGG    D    GGG         ", "            GGGC CGGG            ", "                                 ")
                .aisle("             CCCCCCC             ", "           GGGGC CGGGG           ", "         GG  DDDDDDD  GG         ", "       GG               GG       ", "      G                   G      ", "     G                     G     ", "    G                       G    ", "   G                         G   ", "   G                         G   ", "  G                           G  ", "  G                           G  ", " G                             G ", " G                             G ", " GD                           DG ", " GD                           DG ", "CCD                           DCC", "  D                           D  ", "CCD                           DCC", " GD                           DG ", " GD                           DG ", " G                             G ", " G                             G ", "  G                           G  ", "  G                           G  ", "   G                         G   ", "   G                         G   ", "    G                       G    ", "     G                     G     ", "      G                   G      ", "       GG               GG       ", "         GG  DDDDDDD  GG         ", "           GGGGC CGGGG           ", "               C C               ")
                .aisle("            CCHHHHHCC            ", "          GGGGDDDDDGGGG          ", "        GG  DD     DD  GG        ", "       G                 G       ", "      G                   G      ", "     G E                 E G     ", "    G                       G    ", "   G E                     E G   ", "  G                           G  ", "  G                           G  ", " G                             G ", " G                             G ", " GD                           DG ", " GD                           DG ", " D                             D ", "CD                             DC", " D                             D ", "CD                             DC", " D                             D ", " GD                           DG ", " GD                           DG ", " G                             G ", " G                             G ", "  G                           G  ", "  G                           G  ", "   G E                     E G   ", "    G                       G    ", "     G E                 E G     ", "      G                   G      ", "       G                 G       ", "        GG  DD     DD  GG        ", "          GGGGDDDDDGGGG          ", "               C C               ")
                .aisle("            CHHHHHHHC            ", "          GGGDDCDCDDGGG          ", "        GG  D  EEE  D  GG        ", "       G                 G       ", "      C                   C      ", "     G E                 E G     ", "    C                       C    ", "   G E                     E G   ", "  G                           G  ", "  G                           G  ", " G                             G ", " G                             G ", " GD                           DG ", " D                             D ", " D                             D ", "CCE                           ECC", " DE                           ED ", "CCE                           ECC", " D                             D ", " D                             D ", " GD                           DG ", " G                             G ", " G                             G ", "  G                           G  ", "  G                           G  ", "   G E                     E G   ", "    C                       C    ", "     G E                 E G     ", "      C                   C      ", "       G                 G       ", "        GG  D  EEE  D  GG        ", "          GGGDDCDCDDGGG          ", "               C C               ")
                .aisle("            CHHFFFHHC            ", "         CCCCDCCDCCDCCCC         ", "       CCC  D EAAAE D  CCC       ", "      CC                 CC      ", "     CC                   CC     ", "    CC E                 E CC    ", "   CC                       CC   ", "  CC E                     E CC  ", "  C                           C  ", " CC                           CC ", " C                             C ", " C                             C ", "CCD                           DCC", "CD                             DC", "CCE                           ECC", "CCA                           ACC", "CDA                           ADC", "CCA                           ACC", "CCE                           ECC", "CD                             DC", "CCD                           DCC", " C                             C ", " C                             C ", " CC                           CC ", "  C                           C  ", "  CC E                     E CC  ", "   CC                       CC   ", "    CC E                 E CC    ", "     CC                   CC     ", "      CC                 CC      ", "       CCC  D EAAAE D  CCC       ", "         CCCCDCCDCCDCCCC         ", "            CCCCCCCCC            ")
                .aisle("            CHHFSFHHC            ", "             DDDDDDD             ", "          DDD EAAAE DDD          ", "        DD             DD        ", "      CDBB             BBDC      ", "      DB                 BD      ", "    CDB                   BDC    ", "    DB                     BD    ", "   DB                       BD   ", "   DB                       BD   ", "  D                           D  ", "  D                           D  ", "  D                           D  ", " D                             D ", " DE                           ED ", "CDA                           ADC", " DA                           AD ", "CDA                           ADC", " DE                           ED ", " D                             D ", "  D                           D  ", "  D                           D  ", "  D                           D  ", "   DB                       BD   ", "   DB                       BD   ", "    DB                     BD    ", "    CDB                   BDC    ", "      DB                 BD      ", "      CDBB             BBDC      ", "        DD             DD        ", "          DDD EAAAE DDD          ", "             DDDDDDD             ", "               C C               ")
                .aisle("            CHHFFFHHC            ", "         CCCCDCCDCCDCCCC         ", "       CCC  D EAAAE D  CCC       ", "      CC                 CC      ", "     CC                   CC     ", "    CC E                 E CC    ", "   CC                       CC   ", "  CC E                     E CC  ", "  C                           C  ", " CC                           CC ", " C                             C ", " C                             C ", "CCD                           DCC", "CD                             DC", "CCE                           ECC", "CCA                           ACC", "CDA                           ADC", "CCA                           ACC", "CCE                           ECC", "CD                             DC", "CCD                           DCC", " C                             C ", " C                             C ", " CC                           CC ", "  C                           C  ", "  CC E                     E CC  ", "   CC                       CC   ", "    CC E                 E CC    ", "     CC                   CC     ", "      CC                 CC      ", "       CCC  D EAAAE D  CCC       ", "         CCCCDCCDCCDCCCC         ", "            CCCCCCCCC            ")
                .aisle("            CHHHHHHHC            ", "          GGGDDCDCDDGGG          ", "        GG  D  EEE  D  GG        ", "       G                 G       ", "      C                   C      ", "     G E                 E G     ", "    C                       C    ", "   G E                     E G   ", "  G                           G  ", "  G                           G  ", " G                             G ", " G                             G ", " GD                           DG ", " D                             D ", " D                             D ", "CCE                           ECC", " DE                           ED ", "CCE                           ECC", " D                             D ", " D                             D ", " GD                           DG ", " G                             G ", " G                             G ", "  G                           G  ", "  G                           G  ", "   G E                     E G   ", "    C                       C    ", "     G E                 E G     ", "      C                   C      ", "       G                 G       ", "        GG  D  EEE  D  GG        ", "          GGGDDCDCDDGGG          ", "               C C               ")
                .aisle("            CCHHHHHCC            ", "          GGGGDDDDDGGGG          ", "        GG  DD     DD  GG        ", "       G                 G       ", "      G                   G      ", "     G E                 E G     ", "    G                       G    ", "   G E                     E G   ", "  G                           G  ", "  G                           G  ", " G                             G ", " G                             G ", " GD                           DG ", " GD                           DG ", " D                             D ", "CD                             DC", " D                             D ", "CD                             DC", " D                             D ", " GD                           DG ", " GD                           DG ", " G                             G ", " G                             G ", "  G                           G  ", "  G                           G  ", "   G E                     E G   ", "    G                       G    ", "     G E                 E G     ", "      G                   G      ", "       G                 G       ", "        GG  DD     DD  GG        ", "          GGGGDDDDDGGGG          ", "               C C               ")
                .aisle("             CCCCCCC             ", "           GGGGC CGGGG           ", "         GG  DDDDDDD  GG         ", "       GG               GG       ", "      G                   G      ", "     G                     G     ", "    G                       G    ", "   G                         G   ", "   G                         G   ", "  G                           G  ", "  G                           G  ", " G                             G ", " G                             G ", " GD                           DG ", " GD                           DG ", "CCD                           DCC", "  D                           D  ", "CCD                           DCC", " GD                           DG ", " GD                           DG ", " G                             G ", " G                             G ", "  G                           G  ", "  G                           G  ", "   G                         G   ", "   G                         G   ", "    G                       G    ", "     G                     G     ", "      G                   G      ", "       GG               GG       ", "         GG  DDDDDDD  GG         ", "           GGGGC CGGGG           ", "               C C               ")
                .aisle("                                 ", "            GGGC CGGG            ", "         GGG    D    GGG         ", "        G               G        ", "      GG                 GG      ", "     G                     G     ", "    G                       G    ", "    G                       G    ", "   G                         G   ", "  G                           G  ", "  G                           G  ", "  G                           G  ", " G                             G ", " G                             G ", " G                             G ", " C                             C ", "  D                           D  ", " C                             C ", " G                             G ", " G                             G ", " G                             G ", "  G                           G  ", "  G                           G  ", "  G                           G  ", "   G                         G   ", "    G                       G    ", "    G                       G    ", "     G                     G     ", "      GG                 GG      ", "        G               G        ", "         GGG    D    GGG         ", "            GGGC CGGG            ", "                                 ")
                .aisle("                                 ", "             GGC CGG             ", "          GGG   D   GGG          ", "        GG             GG        ", "       G                 G       ", "     GG                   GG     ", "     G                     G     ", "    G                       G    ", "   G                         G   ", "   G                         G   ", "  G                           G  ", "  G                           G  ", "  G                           G  ", " G                             G ", " G                             G ", " C                             C ", "  D                           D  ", " C                             C ", " G                             G ", " G                             G ", "  G                           G  ", "  G                           G  ", "  G                           G  ", "   G                         G   ", "   G                         G   ", "    G                       G    ", "     G                     G     ", "     GG                   GG     ", "       G                 G       ", "        GG             GG        ", "          GGG   D   GGG          ", "             GGC CGG             ", "                                 ")
                .aisle("                                 ", "               C C               ", "           GGGGC CGGGG           ", "         GG     D     GG         ", "       GG       B       GG       ", "      G                   G      ", "     G                     G     ", "    G                       G    ", "    G                       G    ", "   G                         G   ", "   G                         G   ", "  G                           G  ", "  G                           G  ", "  G                           G  ", "  G                           G  ", " CC                           CC ", "   DB                       BD   ", " CC                           CC ", "  G                           G  ", "  G                           G  ", "  G                           G  ", "  G                           G  ", "   G                         G   ", "   G                         G   ", "    G                       G    ", "    G                       G    ", "     G                     G     ", "      G                   G      ", "       GG       B       GG       ", "         GG     D     GG         ", "           GGGGC CGGGG           ", "               C C               ", "                                 ")
                .aisle("                                 ", "                                 ", "             GGC CGG             ", "          GGG   D   GGG          ", "        GG      B      GG        ", "      GG                 GG      ", "     GG                   GG     ", "     G                     G     ", "    G                       G    ", "    G                       G    ", "   G                         G   ", "   G                         G   ", "   G                         G   ", "  G                           G  ", "  G                           G  ", "  C                           C  ", "   DB                       BD   ", "  C                           C  ", "  G                           G  ", "  G                           G  ", "   G                         G   ", "   G                         G   ", "   G                         G   ", "    G                       G    ", "    G                       G    ", "     G                     G     ", "     GG                   GG     ", "      GG                 GG      ", "        GG      B      GG        ", "          GGG   D   GGG          ", "             GGC CGG             ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "               C C               ", "            GGGC CGGG            ", "         GGG    D    GGG         ", "       GG    EEEBEEE    GG       ", "      G                   G      ", "     G                     G     ", "     G                     G     ", "    G                       G    ", "    G                       G    ", "    G                       G    ", "   G                         G   ", "   G E                     E G   ", "   G E                     E G   ", "  CC E                     E CC  ", "    DB                     BD    ", "  CC E                     E CC  ", "   G E                     E G   ", "   G E                     E G   ", "   G                         G   ", "    G                       G    ", "    G                       G    ", "    G                       G    ", "     G                     G     ", "     G                     G     ", "      G                   G      ", "       GG    EEEBEEE    GG       ", "         GGG    D    GGG         ", "            GGGC CGGG            ", "               C C               ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "                                 ", "               C C               ", "           GGGCCCCCGGG           ", "        GGG     D     GGG        ", "       GG       B       GG       ", "      G                   G      ", "     GG                   GG     ", "     G                     G     ", "     G                     G     ", "    G                       G    ", "    G                       G    ", "    G                       G    ", "    C                       C    ", "   CC                       CC   ", "    CDB                   BDC    ", "   CC                       CC   ", "    C                       C    ", "    G                       G    ", "    G                       G    ", "    G                       G    ", "     G                     G     ", "     G                     G     ", "     GG                   GG     ", "      G                   G      ", "       GG       B       GG       ", "        GGG     D     GGG        ", "           GGGCCCCCGGG           ", "               C C               ", "                                 ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "                                 ", "                                 ", "               C C               ", "          GGGGGC CGGGGG          ", "        GGG     D     GGG        ", "       GG    EEEBEEE    GG       ", "      GG                 GG      ", "      G                   G      ", "     GG                   GG     ", "     G                     G     ", "     G                     G     ", "     G E                 E G     ", "     G E                 E G     ", "    CC E                 E CC    ", "      DB                 BD      ", "    CC E                 E CC    ", "     G E                 E G     ", "     G E                 E G     ", "     G                     G     ", "     G                     G     ", "     GG                   GG     ", "      G                   G      ", "      GG                 GG      ", "       GG    EEEBEEE    GG       ", "        GGG     D     GGG        ", "          GGGGGC CGGGGG          ", "               C C               ", "                                 ", "                                 ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "               C C               ", "           GGGCCCCCGGG           ", "         GGG    D    GGG         ", "        GG      B      GG        ", "       GG       B       GG       ", "       G                 G       ", "      GG                 GG      ", "      G                   G      ", "      G                   G      ", "      C                   C      ", "     CC                   CC     ", "      CDBB             BBDC      ", "     CC                   CC     ", "      C                   C      ", "      G                   G      ", "      G                   G      ", "      GG                 GG      ", "       G                 G       ", "       GG       B       GG       ", "        GG      B      GG        ", "         GGG    D    GGG         ", "           GGGCCCCCGGG           ", "               C C               ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "               C C               ", "            GGGC CGGG            ", "          GGG   D   GGG          ", "         GG     D     GG         ", "        GG             GG        ", "        G               G        ", "       GG               GG       ", "       G                 G       ", "       G                 G       ", "      CC                 CC      ", "        DD             DD        ", "      CC                 CC      ", "       G                 G       ", "       G                 G       ", "       GG               GG       ", "        G       D       G        ", "        GG      D      GG        ", "         GG     D     GG         ", "          GGG   D   GGG          ", "            GGGC CGGG            ", "               C C               ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "               C C               ", "             GGC CGG             ", "           GGGGC CGGGG           ", "          GGG   D   GGG          ", "         GGG    D    GGG         ", "         GG  DDDDDDD  GG         ", "        GG  DD     DD  GG        ", "        GG  D  EEE  D  GG        ", "       CCC  D EAAAE D  CCC       ", "          DDD EAAAE DDD          ", "       CCC  D EAAAE D  CCC       ", "        GG  D  EEE  D  GG        ", "        GG  DD     DD  GG        ", "         GG  DDDDDDD  GG         ", "         GGG    D    GGG         ", "          GGG   D   GGG          ", "           GGGGC CGGGG           ", "             GGC CGG             ", "               C C               ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "               C C               ", "             GGC CGG             ", "            GGGC CGGG            ", "           GGGGC CGGGG           ", "          GGGGDDDDDGGGG          ", "          GGGDDCDCDDGGG          ", "         CCCCDCCDCCDCCCC         ", "             DDDDDDD             ", "         CCCCDCCDCCDCCCC         ", "          GGGDDCDCDDGGG          ", "          GGGGDDDDDGGGG          ", "           GGGGC CGGGG           ", "            GGGC CGGG            ", "             GGC CGG             ", "               C C               ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ")
                .aisle("                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "               C C               ", "               C C               ", "               C C               ", "            CCCCCCCCC            ", "               C C               ", "            CCCCCCCCC            ", "               C C               ", "               C C               ", "               C C               ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ", "                                 ")
                .where('S', this.selfPredicate())
                .where('A', states(getCasingState()))
                .where('B', states(getSecondCasingState()))
                .where('C', states(getThirdCasingState()))
                .where('D', states(getCoilState()))
                .where('E', states(getFourthCasingState()))
                .where('F', states(getFifthCasingState())
                        .or(abilities(MultiblockAbility.IMPORT_FLUIDS) // for Helium Plasma input
                                .setExactLimit(1))
                        .or(autoAbilities(true, true, true, true, false, true, false)))
                .where('G', states(getSixthCasingState()))
                .where('H', states(getFifthCasingState()))
                .where(' ', any())
                .build();
    }

    private static IBlockState getCasingState() {
        return GTLiteMetaBlocks.SCIENCE_CASING.getState(BlockScienceCasing.ScienceCasingType.DIMENSIONAL_PRESERVE_CASING);
    }

    private static IBlockState getSecondCasingState() {
        return GTLiteMetaBlocks.SCIENCE_CASING.getState(BlockScienceCasing.ScienceCasingType.DIMENSIONAL_BRIDGE_CASING);
    }

    private static IBlockState getThirdCasingState() {
        return GTLiteMetaBlocks.SCIENCE_CASING.getState(BlockScienceCasing.ScienceCasingType.ADVANCED_HIGH_ENERGY_CASING);
    }

    private static IBlockState getCoilState() {
        return GTLiteMetaBlocks.SCIENCE_CASING.getState(BlockScienceCasing.ScienceCasingType.MOLECULAR_COIL);
    }

    private static IBlockState getFourthCasingState() {
        return GTLiteMetaBlocks.SCIENCE_CASING.getState(BlockScienceCasing.ScienceCasingType.SPACETIME_CASING);
    }

    private static IBlockState getFifthCasingState() {
        return MetaBlocks.COMPUTER_CASING.getState(BlockComputerCasing.CasingType.HIGH_POWER_CASING);
    }

    private static IBlockState getSixthCasingState() {
        return GTLiteMetaBlocks.SCIENCE_CASING.getState(BlockScienceCasing.ScienceCasingType.ULTIMATE_HIGH_ENERGY_CASING);
    }

    @SideOnly(Side.CLIENT)
    @Override
    public ICubeRenderer getBaseTexture(IMultiblockPart iMultiblockPart) {
        return iMultiblockPart == null ? GTLiteTextures.ULTIMATE_HIGH_ENERGY_CASING : Textures.HIGH_POWER_CASING;
    }

    @SideOnly(Side.CLIENT)
    @NotNull
    @Override
    protected ICubeRenderer getFrontOverlay() {
        return GTLiteTextures.VIRTUAL_COSMOS_SIMULATOR_OVERLAY;
    }

    @Override
    public boolean canBeDistinct() {
        return true;
    }

    @Override
    public void addInformation(ItemStack stack,
                               @Nullable World player,
                               @NotNull List<String> tooltip,
                               boolean advanced) {
        super.addInformation(stack, player, tooltip, advanced);
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.1"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.2"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.3"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.4"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.5"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.6"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.7"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.8"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.9"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.10"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.11"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.12"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.13"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.14"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.15"));
        tooltip.add(I18n.format("gtlitecore.machine.virtual_cosmos_simulator.tooltip.16"));
    }

    @Override
    protected void addDisplayText(List<ITextComponent> textList) {
        if (isStructureFormed()) {
            if (getInputFluidInventory() != null) {
                FluidStack HydrogenStack = this.getInputFluidInventory().drain(Hydrogen.getFluid(Integer.MAX_VALUE), false);
                FluidStack HeliumStack = this.getInputFluidInventory().drain(Helium.getFluid(Integer.MAX_VALUE), false);
                int hydrogenAmount = HydrogenStack == null ? 0 : HydrogenStack.amount;
                int heliumAmount = HeliumStack == null ? 0 : HeliumStack.amount;
                textList.add(new TextComponentTranslation("gtlitecore.machine.virtual_cosmos_simulator.hydrogen_amount", GTLiteUtility.formatNumbers(hydrogenAmount)));
                textList.add(new TextComponentTranslation("gtlitecore.machine.virtual_cosmos_simulator.helium_amount", GTLiteUtility.formatNumbers(heliumAmount)));
            }
        }
        super.addDisplayText(textList);
    }

    @Override
    protected void addWarningText(List<ITextComponent> textList) {
        super.addWarningText(textList);
        if (isStructureFormed()) {
            FluidStack hydrogenStack = this.getInputFluidInventory().drain(Hydrogen.getFluid(Integer.MAX_VALUE), false);
            FluidStack heliumStack = this.getInputFluidInventory().drain(Helium.getFluid(Integer.MAX_VALUE), false);
            if (hydrogenStack == null || hydrogenStack.amount == 0) {
                textList.add(new TextComponentTranslation("gtlitecore.machine.virtual_cosmos_simulator.hydrogen_warning"));
            }
            if (heliumStack == null || heliumStack.amount == 0) {
                textList.add(new TextComponentTranslation("gtlitecore.machine.virtual_cosmos_simulator.helium_warning"));
            }
        }
    }

    private class VirtualCosmosSimulatorRecipeLogic extends MultiblockRecipeLogic {

        public final FluidStack HYDROGEN_STACK = Hydrogen.getFluid(1000000);
        public final FluidStack HELIUM_STACK = Helium.getFluid(1000000);

        public VirtualCosmosSimulatorRecipeLogic(RecipeMapMultiblockController tileEntity) {
            super(tileEntity);
        }

        @Override
        protected void updateRecipeProgress() {
            if (canRecipeProgress && drawEnergy(recipeEUt, true)) {
                IMultipleTankHandler inputTank = getInputFluidInventory();
                if (HYDROGEN_STACK.isFluidStackIdentical(inputTank.drain(HYDROGEN_STACK, false))) {
                    inputTank.drain(HYDROGEN_STACK, true);
                    if (HELIUM_STACK.isFluidStackIdentical(inputTank.drain(HELIUM_STACK, false))) {
                        inputTank.drain(HELIUM_STACK, true);
                        if (++progressTime > maxProgressTime) {
                            completeRecipe();
                        }
                    }
                }
                else return;
                drawEnergy(recipeEUt, false);
            }
        }
    }
}
